--[[ 编码: hh-mobox-002 名称: 货位状态 作者:SGX 日期:2024-11-27 函数: GenChartJson 功能: 叠柱状图 更改记录: --]] json = require("json") mobox = require("OILua_JavelinExt") m3 = require("oi_base_mobox") function GenChartJson1(strLuaDEID) local nRet, strRetInfo --[[ 标题颜色 ]] local strTitle = "物料数量" --[[ 文字颜色 ]] local strColor = "#fff" --[[ 柱状图柱子名称,对应 series 下name ]] local tabLegendData = { '数量' } --[[ X轴数据 从左向右 ]] local tabXAxis = { '胶料', '钢丝', '粉料', '辅材', '碳黑', '帘子布' } --[[ Y轴 最上方显示文字 ]] local strYAxisName = "物料数量" --[[ 满仓颜色 ]] local strMCColor = '#45A048' --[[ 空仓颜色 ]] -- local strKCColor = '#FE9700' --[[ 柱状图数据 对应X轴数据 ]] --[[ 满仓 ]] -- local tabSeriesMCData = {} -- for i = 1, 6 do -- -- 获取对应物料的总托数 -- local item_type = tabXAxis[i] -- -- 获取物料的托数 -- tabSeriesMCData[i] = lua.StrToNumber(29) -- end local jl_num = 0 local gs_num = 0 local fl_num = 0 local fc_num = 0 local th_num = 0 local lzb_num = 0 local strCondition = "S_CNTR_CODE IN (SELECT S_CNTR_CODE FROM TN_Loc_Container)" local nRet, cg_detail = mobox.queryDataObjAttr2(strLuaDEID, "CG_Detail", strCondition, "", 100, "S_ITEM_CODE") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "查询【容器货品明细】信息失败!" .. cg_detail) end if (cg_detail == nil or cg_detail == '') then return end local queryInfo = json.decode(cg_detail) local nPageCount = queryInfo.pageCount local dataSet = queryInfo.dataSet local queryID = queryInfo.queryID lua.Debug(strLuaDEID, debug.getinfo(1), 'queryInfo:', queryInfo) -- 分页获取货位的数据 for i = 1, nPageCount do for j = 1, #dataSet do local attrs nRet, attrs = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(dataSet[j].attrs)) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "ObjAttrStrToLuaObj失败!" .. attrs) end -- 通过物料编码获取物料类型 local item_type_new, material nRet, item_type_new, material = GT_Get_ItemType(strLuaDEID, attrs.item_code) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), item_type_new) end if (item_type_new == '胶料' or item_type_new == '天然胶' or item_type_new == '散装胶') then jl_num = jl_num + 1 elseif (item_type_new == '钢丝') then gs_num = gs_num + 1 elseif (item_type_new == '粉料') then fl_num = fl_num + 1 elseif (item_type_new == '辅材') then fc_num = fc_num + 1 elseif (item_type_new == '碳黑') then th_num = th_num + 1 elseif (item_type_new == '帘子布') then lzb_num = lzb_num + 1 end end if ((i + 1) <= nPageCount) then -- 取下一页 local data nRet, data = mobox.queryDataObjAttr2(queryID, (i + 1)) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "queryDataObjAttr2失败! nPage=" .. i + 1 .. " " .. data) end data = json.decode(data) dataSet = data.dataSet end end local tabSeriesMCData = { jl_num, gs_num, fl_num, fc_num, th_num, lzb_num } --[[ 空仓 ]] -- local tabSeriesKCData = {} -- for i = 1 ,8 do -- local strCondition = "N_ROADWAY = "..i.." AND N_CURRENT_NUM = 0" -- nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Location", strCondition) -- if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "getDataObjCount 失败! " .. strRetInfo) end -- tabSeriesKCData[i] = lua.StrToNumber(strRetInfo) -- end -- local option = { -- title = { -- text = strTitle, -- left = 20, -- textStyle = { -- color = strColor -- }, -- top = 10 -- }, -- legend = { -- data = tabLegendData, -- textStyle = { -- color = strColor -- }, -- top = 10 -- }, -- grid = { -- left = '5%', -- right = '5%', -- bottom = '5%', -- top = '22%', -- containLabel = true -- }, -- xAxis = { -- type = 'category', -- data = tabXAxis, -- axisLabel = { -- textStyle = { -- color = strColor -- } -- } -- }, -- yAxis = { -- type = 'value', -- nameTextStyle = { -- color = strColor -- }, -- axisLabel = { -- textStyle = { -- color = strColor -- } -- } -- }, -- series = { { -- name = '数量', -- type = 'bar', -- stack = 'total', -- label = { -- show = true -- }, -- color = strMCColor, -- data = tabSeriesMCData -- } } -- } local option = { xAxis = { type = 'category', data = { '胶料', '钢丝', '粉料', '辅材', '碳黑', '帘子布' } }, yAxis = { type = 'value' }, series = { { data = { jl_num, gs_num, fl_num, fc_num, th_num, lzb_num }, type = 'bar' } } }; local action = {} action[1] = { action_type = "chart", value = { graphicType = "echart", title = { text = strTitle, align = "center", color = "#515a6e", font = "微软雅黑", fontSize = 12 }, option = option } } lua.Debug( strLuaDEID, debug.getinfo(1), "action! ", action ) nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action)) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "setAction失败! " .. strRetInfo .. ' action = ' .. strAction) end end